import { observable } from 'mobx'
import { topicListApi } from '../config/api';

class topicStore {
    @observable 
    topic = {
        data: [],
        page: 1,
        tab: '',
        loading: true
    }

    constructor () {
       this.getData()
    }

    getData = () => {
        const { tab, page } = this.topic
        this.topic.loading = true
        topicListApi(page, tab).then((data: any) => {
            if (data.success) {
                this.topic = {
                    ...this.topic,
                    data: data.data,
                    loading: false
                }
            }
          
        })
    }
    
    filter = (tab: string) => {
		this.topic.tab = tab
        return this.getData()
	}

	flip = (page: number) => {
		this.topic.page = page
        this.getData()
	}
}

export default new topicStore();



